import Mock, { Random } from 'mockjs';
import uuid from 'uuid/v4';
import { output, queryString } from '../help';
// import { makeItem } from '../item';

function makeTel() {
  const head = ['134', '135', '158', '182'][parseInt(Math.random() * 4)];
  const indexArr = Array.from(Array.apply(null, {length: 8}).keys());
  const body = indexArr.map(() => parseInt(Math.random() * 10));

  return `${head}${body.join('')}`;
}

function makeWinner() {
  return {
    id: Random.increment(),
    name: Random.cname(),
    address: Random.county(true),
    tel: makeTel(),
    prize: Random.ctitle(5, 10),
    // time:
  };
}

Mock.mock(/mock.getWinnersList/, request => {
  const params = queryString(request.url);
  console.log('getItemsList params', params);

  const { pageSize = 10 } = params;
  const list = [];

  for (let i = 0; i < pageSize; i++) {
    list.push(makeWinner());
  }

  return output({
    list,
    total: Random.integer(50, 140),
  });
});

Mock.mock(/mock.getPrizeList/, () => {
  const list = [
    {
      id: 1,
      title: '100天胶原蛋白畅饮权'
    },
    {
      id: 2,
      title: '植物医生施华洛世奇定制礼盒'
    },
    {
      id: 3,
      title: '门店代金券'
    },
    {
      id: 4,
      title: '天猫代金券'
    },
  ];

  return output({
    count: 4,
    list,
  });
});



